package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.CustFunctionpoint;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.service.FunctionpointService;
import sjtu.ist.warehouse4ws.service.cust.CustFunctionpointService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowFunctionListAction extends ActionSupport {

	private FunctionpointService functionpointService;
	private CustFunctionpointService custFunctionpointService;
	private List<Functionpoint> functionList = new ArrayList<Functionpoint>();
	private String gid;
	private String vid;
	
	public void setCustFunctionpointService(
			CustFunctionpointService custFunctionpointService) {
		this.custFunctionpointService = custFunctionpointService;
	}

	//获得Function列表
	public String showFunctionList(){
		
		
		Subject currentUser = SecurityUtils.getSubject();		
		Integer company=(Integer) currentUser.getSession().getAttribute("companyId");
		
		if(!currentUser.hasRole("superadmin"))
		{
			List<CustFunctionpoint> templist=custFunctionpointService.getCustFunctionpointList();
			this.functionList = new ArrayList<Functionpoint>();
			for(CustFunctionpoint f : templist){
				//if(privilegeService.checkPrivilege(f.getFileId(),userCompany,userType, "read")){
					functionList.add( f);
				//}
			}
		}
		else
		{
			//functionList=functionpointService.getFunctionpointList();
			functionList=functionpointService.getFunctionpointListByGroupAndVersion(gid,vid,company);
		}
		return SUCCESS;
	}
	
	@JSON(name = "totalFunction")
	public int getTotalFunction() {
		return this.functionList.size();
	}

	@JSON(name = "Function")
	public List<Functionpoint> getFunctionList() {
		return this.functionList;
	}
	
	// 注入FunctionpointService
	public void setFunctionpointService(FunctionpointService functionpointService) {
		this.functionpointService = functionpointService;
	}

	public String getGid() {
		return gid;
	}

	public void setGid(String gid) {
		this.gid = gid;
	}

	public String getVid() {
		return vid;
	}

	public void setVid(String vid) {
		this.vid = vid;
	}
	
	
	
}